/* 学习档案API */
import { http } from '@/utils/http'

export interface CourseItem {
  courseName: string
  studyStartTime: string
  studyEndTime: string
}

export interface CourseData {
  totalCount: number
  items: CourseItem[]
}

export interface ExamItem {
  examTitle: string
  examTime: string
  score: number
  passScore: number
  totalScore: number
  passStr: string
}

export interface ExamData {
  totalCount: number
  items: ExamItem[]
}

export interface KnowledgeItem {
  resourceName: string
  sortName: string
}

export interface KnowledgeData {
  totalCount: number
  items: KnowledgeItem[]
}

export interface TrainingItem {
  name: string
  short_stime: string
  short_etime: string
  finishLesson: number
  passStr: string
}

export interface TrainingData {
  totalCount: number
  items: TrainingItem[]
}

/* 课程 */
export const getCourseList = ({
  Type,
  startTime,
  endTime,
  paStatus,
  types,
  page,
  limit = 1000,
}: {
  Type?: number[]
  startTime?: string
  endTime?: string
  paStatus?: number
  types?: string
  page?: number
  limit?: number
} = {}): Promise<IResData<CourseData>> => {
  return http.get<CourseData>('/api/MP/GetMyLearningCourses', {
    Type,
    startTime,
    endTime,
    paStatus,
    types,
    page,
    limit,
  })
}

/* 考试 */
export const getExamList = ({
  Type,
  startTime,
  endTime,
  paStatus, // 未通过 0 已通过 1
  types,
  page,
  limit = 1000,
}: {
  Type?: number[]
  startTime?: string
  endTime?: string
  paStatus?: number
  types?: string
  page?: number
  limit?: number
} = {}): Promise<IResData<ExamData>> => {
  return http.get<ExamData>('/api/MP/GetExamList', {
    Type,
    startTime,
    endTime,
    paStatus,
    types,
    page,
    limit,
  })
}

/* 知识列表 */
export const getKnowledgeList = ({
  Type,
  startTime,
  endTime,
  paStatus,
  types,
  page,
  limit = 1000,
}: {
  Type?: number[]
  startTime?: string
  endTime?: string
  paStatus?: number
  types?: string
  page?: number
  limit?: number
} = {}): Promise<IResData<KnowledgeData>> => {
  return http.get<KnowledgeData>('/api/MP/GetKnowledgeList', {
    Type,
    startTime,
    endTime,
    paStatus,
    types,
    page,
    limit,
  })
}

/* 培训列表 */
export const getTrainingList = ({
  showFlag,
  deptId,
  trainName,
  teacherName,
  startTime,
  endTime,
  page,
  limit = 1000,
}: {
  showFlag?: number
  deptId?: number
  trainName?: string
  teacherName?: string
  startTime?: string
  endTime?: string
  page?: number
  limit?: number
} = {}): Promise<IResData<TrainingData>> => {
  return http.get<TrainingData>('/api/MP/GetTrainList', {
    showFlag,
    deptId,
    trainName,
    teacherName,
    startTime,
    endTime,
    page,
    limit,
  })
}
